package com.kongge.viewdisplayframeworklib.model;

import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;

import com.kongge.viewdisplayframeworklib.event.param.EQParam;
import com.kongge.viewdisplayframeworklib.landscape.ISavePageState;
import com.kongge.viewdisplayframeworklib.ui.Component;
import com.kongge.viewdisplayframeworklib.util.EQConstans;

import java.io.Serializable;
import java.util.Vector;

/**
 * author:kongge
 * date:2018/9/12
 * layout:
 * description:
 */

public abstract class AbsUIController {

    protected static final int EVENT_ONFOREGOUND = 1;
    protected static final int EVENT_ONBACKGROUND = 2;
    protected static final int EVENT_ONPAGEFINISHLOAD = 3;
    protected static final int EVENT_ONREMOVE = 4;

    protected PageNode pageNode;
    protected ViewGroup mViewGroup;

    private Serializable info;

    public AbsUIController(PageNode pageNode, ViewGroup viewGroup) {
        this.pageNode = pageNode;
        this.mViewGroup = viewGroup;
    }

    public abstract void dispatchParam(EQParam param);

    public abstract void dispatchEvent(int event);

    public View getRootView() {
        return (View) mViewGroup;
    }

    public int getPageId() {
        if (pageNode != null) {
            return pageNode.getPageId();
        }
        return EQConstans.INVALID_ID;
    }

    public int getStackLevel() {
        if (pageNode != null) {
            return pageNode.getStackLevel();
        }
        return EQConstans.INVALID_ID;
    }

    public String getTitle() {
        if (pageNode != null) {
            return pageNode.getTitle();
        }
        return EQConstans.INVALID_STR;
    }

    public void setTitle(String title) {
        if (pageNode != null) {
            pageNode.setTitle(title);
        }
    }

    public void onForeground() {
        dispatchEvent(EVENT_ONFOREGOUND);
    }

    public void onBackground() {
        dispatchEvent(EVENT_ONBACKGROUND);
    }

    public void onRemove() {
        dispatchEvent(EVENT_ONREMOVE);
    }

    public abstract boolean isBottomBarVisible();

    public abstract NavigateItem getNavigateItem();

    public abstract boolean onKeyDown(int keyCode, KeyEvent event);

    public abstract void broadcastScreenChange();

    public Serializable getInfo() {
        return info;
    }

    public void setInfo(Serializable info) {
        this.info = info;
    }
}
